<!--
* description: 调拨计划查询
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicApiConfig="apiConfig"
      :dynamicTableCols="tableCols"
      :dynamicFormFields="formField"
      :dynamicUnFormFields="unFormField"
      :dynamicIsShowSelect="false"
      :dynamicIsColumnDrop="true"
      :dynamicIsInitTable="true"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { wmsApis } from "@/api/wms/allocation/api";
import OneTableTemplate from "@/components/wms/templates/oneTable";
import request from "@/utils/request";
import store from "@/store";
export default {
  name: "packingMaterialOptimization",
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],
  components: {
    OneTableTemplate
  },
  watch: {
    $route(val) {
      if (
        this.formField.pageId !== "" &&
        this.$route.query.pageId !== undefined &&
        this.$route.query.pageId !== this.formField.pageId
      ) {
        this.formField.pageId = this.$route.query.pageId;
        this.formField.pageName = this.$route.query.pageName;
        this.queryTable();
      }
    }
  },
  created() {
    if (this.$route.query != null) {
      // 判断传入query参数，初始化数据
      if (this.$route.query.pageId != null && this.$route.query.pageId !== "") {
        this.formField.pageId = this.$route.query.pageId;
        this.formField.pageName = this.$route.query.pageName;
      }
    }
  },
  mounted() {
    this.querySelect();
  },
  data() {
    return {
      // 网格查询API配置对象
      apiConfig: wmsApis.queryAllocation,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.queryTable(),
          name: "search",
          position: "right",
          text: "查询" //"查询"
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          name: "reset",
          position: "right",
          clickEvent: () => this.reset(),
          text: "重置"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "compKey1",
          labelName: "源仓库",
          codeField: "SOURCE_WAREHOUSE",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          options: []
        },
        {
          compKey: "compKey2",
          labelName: "目标仓库",
          codeField: "TARGET_WAREHOUSE",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          options: []
        },
        {
          compKey: "compKey3",
          labelName: "备件编号",
          codeField: "PART_NO",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey4",
          labelName: "计划状态",
          codeField: "ALLOCATION_STATUS",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          options: []
        },
        {
          compKey: "compKey5",
          labelName: "调拨计划",
          codeField: "ALLOCATION_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        }
      ],
      // 动态生成网格列
      tableCols: [
        {
          prop: "ALLOCATION_CODE",
          label: "调拨计划",
          align: "center"
        },
        {
          prop: "SOURCE_WAREHOUSE_NAME",
          label: "源仓库",
          align: "center"
        },
        {
          prop: "TARGET_WAREHOUSE_NAME",
          label: "目标仓库",
          align: "center"
        },
        {
          prop: "PART_NO",
          label: "备件编号",
          align: "center"
        },
        {
          prop: "PART_NAME",
          label: "备件名称",
          align: "center"
        },
        {
          prop: "ALLOCATION_QTY",
          label: "调拨数量",
          align: "center"
        },
        {
          prop: "SOURCE_QTY",
          label: "源仓库可用库存",
          align: "center"
        },
        {
          prop: "TARGET_QTY",
          label: "目标仓库可用库存",
          align: "center"
        },
        {
          prop: "ALLOCATION_STATUS_NAME",
          label: "计划状态",
          align: "center"
        },
        {
          prop: "REJECT_REASON",
          label: "驳回原因",
          align: "center"
        }
      ],
      //表单查询数据
      formField: {
        SOURCE_WAREHOUSE: "",
        TARGET_WAREHOUSE: "",
        ALLOCATION_STATUS: "",
        PART_NO: "",
        ALLOCATION_CODE: ""
      },
      unFormField: {}
    };
  },
  methods: {
    querySelect() {
      request({
        url: "/mp/wm/vl/basedata/warehouse/querywarehouse.do",
        method: "post",
        data: {
          IS_ENABLE: "1"
        }
      }).then(res => {
        if (
          res.listResult &&
          res.listResult.rows &&
          res.listResult.rows.length > 0
        ) {
          res.listResult.rows.map(item => {
            this.tableComponents[0].options.push({
              label: item.WAREHOUSE_NAME,
              value: item.WAREHOUSE_ID
            });
          });
        }
      });

      request({
        url: "/mp/wm/vl/basedata/warehouseuser/queryUserByWHBox.do",
        method: "post",
        data: {
          IS_ENABLE: "1"
        }
      }).then(res => {
        if (res.listRow && res.listRow.length > 0) {
          res.listRow.map(item => {
            this.tableComponents[1].options.push({
              label: item.WAREHOUSE_NAME,
              value: item.WAREHOUSE_ID
            });
          });
        }
      });

      request({
        url: "/mp/wm/vl/warehouse/allocation/queryAllocationStatusBox.do",
        method: "post",
        data: {}
      }).then(res => {
        if (res.listRow && res.listRow.length > 0) {
          res.listRow.map(item => {
            this.tableComponents[3].options.push({
              label: item.ALLOCATION_STATUS_NAME,
              value: item.ALLOCATION_STATUS
            });
          });
        }
      });
    }
  }
};
</script>
